using System;
using System.Collections.Generic;
using AGG;
using AGG.Image;
using AGG.VertexSource;
using AGG.UI;

using AGG.Transform;

using Reflexive.Math;
using Reflexive.Game;
using Reflexive.Graphics;

namespace RockBlaster
{
    /// <summary>
    /// Description of HowManyPlayersMenu.
    /// </summary>
    public class HowManyPlayersMenu : GUIWidget
    {
        public delegate void StartOnePlayerGameEventHandler(GUIWidget button);
        public event StartOnePlayerGameEventHandler StartOnePlayerGame;

        public delegate void StartTwoPlayerGameEventHandler(GUIWidget button);
        public event StartTwoPlayerGameEventHandler StartTwoPlayerGame;

        public delegate void StartFourPlayerGameEventHandler(GUIWidget button);
        public event StartFourPlayerGameEventHandler StartFourPlayerGame;

        public delegate void CancelMenuEventHandler(GUIWidget button);
        public event CancelMenuEventHandler CancelMenu;

        public HowManyPlayersMenu(rect_d bounds)
        {
            Bounds = bounds;
            ImageSequence onePlayerButtonSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "OnePlayerButton");
            ButtonWidget onePlayerGameButton = new ButtonWidget(270, 310, new ThreeImageButtonView(onePlayerButtonSequence.GetImageByIndex(0), onePlayerButtonSequence.GetImageByIndex(1), onePlayerButtonSequence.GetImageByIndex(2)));
            AddChild(onePlayerGameButton);
            onePlayerGameButton.Click += new ButtonWidget.ButtonEventHandler(OnStartOnePlayerGameButton);

            ImageSequence twoPlayerButtonSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "TwoPlayerButton");
            ButtonWidget twoPlayerGameButton = new ButtonWidget(400, 310, new ThreeImageButtonView(twoPlayerButtonSequence.GetImageByIndex(0), twoPlayerButtonSequence.GetImageByIndex(1), twoPlayerButtonSequence.GetImageByIndex(2)));
            AddChild(twoPlayerGameButton);
            twoPlayerGameButton.Click += new ButtonWidget.ButtonEventHandler(OnStartTwoPlayerGameButton);

            ImageSequence fourPlayerButtonSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "FourPlayerButton");
            ButtonWidget fourPlayerGameButton = new ButtonWidget(530, 310, new ThreeImageButtonView(fourPlayerButtonSequence.GetImageByIndex(0), fourPlayerButtonSequence.GetImageByIndex(1), fourPlayerButtonSequence.GetImageByIndex(2)));
            AddChild(fourPlayerGameButton);
            fourPlayerGameButton.Click += new ButtonWidget.ButtonEventHandler(OnStartFourPlayerGameButton);

            ImageSequence cancelButtonSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "NumPlayersCancelButton");
            ButtonWidget cancelGameButton = new ButtonWidget(400, 210, new ThreeImageButtonView(cancelButtonSequence.GetImageByIndex(0), cancelButtonSequence.GetImageByIndex(1), cancelButtonSequence.GetImageByIndex(2)));
            AddChild(cancelGameButton);
            cancelGameButton.Click += new ButtonWidget.ButtonEventHandler(OnCancelMenuButton);
        }

        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageSequence menuBackground = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "NumPlayersSelectBackground");
            graphics2D.Render(menuBackground.GetImageByIndex(0), 0, 0);

            base.OnDraw(graphics2D);
        }

        private void OnStartOnePlayerGameButton(object sender, MouseEventArgs mouseEvent)
        {
            if (StartOnePlayerGame != null)
            {
                StartOnePlayerGame(this);
            }
        }

        private void OnStartTwoPlayerGameButton(object sender, MouseEventArgs mouseEvent)
        {
            if (StartTwoPlayerGame != null)
            {
                StartTwoPlayerGame(this);
            }
        }

        private void OnStartFourPlayerGameButton(object sender, MouseEventArgs mouseEvent)
        {
            if (StartFourPlayerGame != null)
            {
                StartFourPlayerGame(this);
            }
        }

        private void OnCancelMenuButton(object sender, MouseEventArgs mouseEvent)
        {
            if (CancelMenu != null)
            {
                CancelMenu(this);
            }
        }
    }
}
